package com.tarzan.security.service.impl;

import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 * @Package com.tarzan.oauth.service.impl
 * @Title UserDetailsServiceImpl
 * @Description TODO
 * @Author liujinshan
 * @CreateTime 2021/6/29 11:03
 */
/*@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    private static final Logger log = LoggerFactory.getLogger(UserDetailsServiceImpl.class);

    @Autowired
    private RemoteUserService remoteUserService;

    @Autowired
    private RemotPermissionsService remotPermissionsService;*/


    /**
     * Locates the user based on the username. In the actual implementation, the search
     * may possibly be case sensitive, or case insensitive depending on how the
     * implementation instance is configured. In this case, the <code>UserDetails</code>
     * object that comes back may have a username that is of a different case than what
     * was actually requested..
     *
     * @param username the username identifying the user whose data is required.
     * @return a fully populated user record (never <code>null</code>)
     * @throws UsernameNotFoundException if the user could not be found or the user has no
     *                                   GrantedAuthority
     */
/*
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        BaseResponse<SysUserDetailInfoResp> response = remoteUserService.findUserInfoByUserName(username);
        SysUserDetailInfoResp sysUserInfoResp = Optional.ofNullable(response).map(BaseResponse::getData).orElse(null);
        if (null == sysUserInfoResp) {
            throw new UsernameNotFoundException("用户不存在");
        }
        UserDetails userDetails;
        userDetails = getUserDetails(sysUserInfoResp);
        return userDetails;
    }


    private UserDetails getUserDetails(SysUserDetailInfoResp sysUserInfoResp) {
        BaseResponse<List<String>> response = remotPermissionsService.selectMenuPermsByUserId(sysUserInfoResp.getId());
        List<String> permissions = Optional.ofNullable(response).map(BaseResponse::getData).orElse(null);
        return new LoginUser(sysUserInfoResp.getUserName(),sysUserInfoResp.getPassword(),permissions);
    }
}
*/
